#include <iostream>
using namespace std;
//开发一个支持windows和mac平台的UI库(族)，每个平台都有按钮和文本框组件(等级结构)
class UIFactory;
class Button{
    friend class UIFactory;    
public:
    virtual void render()=0;
    virtual ~Button(){}
};
class winbutton:public Button{
public:
    void render(){
        cout<<"渲染windows风格按钮"<<endl;
    }
};
class MacButton:public Button{
public:
    void render(){
        cout<<"渲染mac风格的按钮"<<endl;
    }
};

class TextBox{
    friend class UIFactory;
public:
    virtual void render()=0;
    virtual ~TextBox(){}
};
class WinTextBox:public TextBox{
public:
    void render(){
        cout<<"渲染win风格的搜索框"<<endl;
    }
};

class MacTextBox:public TextBox{
public:
    void render(){
        cout<<"渲染mac风格的文本输入框"<<endl;
    }
};

class UIFactory{
    public:
        virtual Button* createButton()=0;
        virtual TextBox* createTextBox()=0;
        virtual ~UIFactory(){}
};
class WinFactory:public UIFactory{
public:
    Button* createButton(){
       Button* wp=new winbutton();
       return wp;
    }
    TextBox* createTextBox(){
        TextBox * tx=new WinTextBox();
        return tx;
    }
};

class MacFactory:public UIFactory{
public:
    Button* createButton(){
       Button* wp=new MacButton();
       return wp;
    }
    TextBox* createTextBox(){
        TextBox * tx=new MacTextBox();
        return tx;
    }
};


void renderUI(UIFactory* factory){
    factory->createButton()->render();
    factory->createTextBox()->render();
    delete  factory->createButton();
    delete  factory->createTextBox();
}
    
int main(int argc, char * argv[]){
    MacFactory Mac;
    UIFactory * factory=&Mac;
    renderUI(factory);
    WinFactory Win;
    UIFactory *factory1=&Win;
    renderUI(factory1);
    return 0;

}

